/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.io.gpstracker.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author wkedzior
 */
@Entity
@Table(name = "way")
@NamedQueries({
    @NamedQuery(name = "Way.findAll", query = "SELECT w FROM Way w"),
    @NamedQuery(name = "Way.findById", query = "SELECT w FROM Way w WHERE w.id = :id"),
    @NamedQuery(name = "Way.findByName", query = "SELECT w FROM Way w WHERE w.name = :name"),
    @NamedQuery(name = "Way.findByDistance", query = "SELECT w FROM Way w WHERE w.distance = :distance")})
public class Way implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Column(name = "name")
    private String name;
    @Column(name = "distance")
    private Long distance;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "way")
    private List<Waysequence> waysequenceList;
    @JoinColumn(name = "user_id", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User user;

    public Way() {
    }

    public Way(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getDistance() {
        return distance;
    }

    public void setDistance(Long distance) {
        this.distance = distance;
    }

    public List<Waysequence> getWaysequenceList() {
        return waysequenceList;
    }

    public void setWaysequenceList(List<Waysequence> waysequenceList) {
        this.waysequenceList = waysequenceList;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Way)) {
            return false;
        }
        Way other = (Way) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pl.edu.agh.io.gpstracker.model.Way[id=" + id + "]";
    }

}
